home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / DancingText / DancingText.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.2 KB  |  441 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLEncoder;
  15.  
  16. public class DancingText extends Applet implements Runnable, MouseListener {
  17.    private Thread thread;
  18.    private Image buffer;
  19.    // $FF: renamed from: b java.awt.Graphics
  20.    private Graphics field_0;
  21.    private boolean loaded;
  22.    // $FF: renamed from: wi int
  23.    private int field_1;
  24.    // $FF: renamed from: he int
  25.    private int field_2;
  26.    private int pause = 50;
  27.    // $FF: renamed from: Nt int
  28.    private int field_3;
  29.    private int textPause = 2000;
  30.    private int textAmplitude = 5;
  31.    private Color backColor;
  32.    private String statusBarText;
  33.    private AudioClip sound;
  34.    private AudioClip clicSound;
  35.    private AudioClip enterSound;
  36.    private boolean loopSound;
  37.    private String link;
  38.    private String text;
  39.    private String[] lines;
  40.    // $FF: renamed from: fm java.awt.FontMetrics
  41.    private FontMetrics field_4;
  42.    private int wiText;
  43.    private int textHeight = 10;
  44.    private Color textColor;
  45.    private Color enterTextColor;
  46.    private Font normalFont;
  47.    private Font enterFont;
  48.  
  49.    public String getAppletInfo() {
  50.       return "Name: DancingText\r\nAuthor: Taiji Software\r\n";
  51.    }
  52.  
  53.    public DancingText() {
  54.       ((Component)this).addMouseListener(this);
  55.    }
  56.  
  57.    public void register() {
  58.       try {
  59.          URL u = new URL("http://www.taijisoftware.com");
  60.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  61.          this.stop();
  62.       } catch (Exception e) {
  63.          System.out.println(e);
  64.          this.stop();
  65.       }
  66.    }
  67.  
  68.    public void init() {
  69.       String codeBase = null;
  70.  
  71.       try {
  72.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  73.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  74.          codeBase = codeBase.toUpperCase();
  75.       } catch (Exception var9) {
  76.       }
  77.  
  78.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  79.          String regCode = ((Applet)this).getParameter("registration_code");
  80.          if (regCode == null) {
  81.             regCode = ((Applet)this).getParameter("reg_domain");
  82.             if (regCode == null) {
  83.                this.register();
  84.             } else {
  85.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  86.                   codeBase = "WWW." + codeBase;
  87.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  88.                   codeBase = codeBase.substring(4);
  89.                }
  90.  
  91.                char[] chars = new char[codeBase.length()];
  92.                codeBase.getChars(0, codeBase.length(), chars, 0);
  93.                String key = new String("haricot");
  94.                char[] chars2 = new char[key.length()];
  95.                key.getChars(0, key.length(), chars2, 0);
  96.  
  97.                for(int i = 0; i < codeBase.length(); ++i) {
  98.                   int j;
  99.                   if (i >= key.length()) {
  100.                      j = i - key.length() * (i / key.length());
  101.                   } else {
  102.                      j = i;
  103.                   }
  104.  
  105.                   chars[i] += chars2[j];
  106.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  107.                }
  108.  
  109.                String res = new String(chars);
  110.                if (!res.equalsIgnoreCase(regCode)) {
  111.                   this.register();
  112.                }
  113.             }
  114.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  115.             this.register();
  116.          }
  117.       }
  118.  
  119.       this.getParameters();
  120.       if (this.sound != null) {
  121.          if (this.loopSound) {
  122.             this.sound.loop();
  123.             return;
  124.          }
  125.  
  126.          this.sound.play();
  127.       }
  128.  
  129.    }
  130.  
  131.    public void getParameters() {
  132.       this.field_1 = ((Component)this).getSize().width;
  133.       this.field_2 = ((Component)this).getSize().height;
  134.       this.text = ((Applet)this).getParameter("text");
  135.       String s = ((Applet)this).getParameter("pause");
  136.       if (s != null) {
  137.          this.pause = Integer.parseInt(s);
  138.       }
  139.  
  140.       s = ((Applet)this).getParameter("text_pause");
  141.       if (s != null) {
  142.          this.textPause = Integer.parseInt(s);
  143.       }
  144.  
  145.       s = ((Applet)this).getParameter("text_amplitude");
  146.       if (s != null) {
  147.          this.textAmplitude = Integer.parseInt(s);
  148.       }
  149.  
  150.       ((Component)this).setBackground(this.getColor("background_color"));
  151.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  152.       s = ((Applet)this).getParameter("sound_name");
  153.       if (s != null) {
  154.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  155.       }
  156.  
  157.       s = ((Applet)this).getParameter("loop_sound");
  158.       if (s != null) {
  159.          if (s.equals("yes")) {
  160.             this.loopSound = true;
  161.          } else {
  162.             this.loopSound = false;
  163.          }
  164.       }
  165.  
  166.       s = ((Applet)this).getParameter("clic_sound_name");
  167.       if (s != null) {
  168.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  169.       }
  170.  
  171.       s = ((Applet)this).getParameter("enter_sound_name");
  172.       if (s != null) {
  173.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  174.       }
  175.  
  176.       this.link = ((Applet)this).getParameter("link");
  177.       s = ((Applet)this).getParameter("text_height");
  178.       if (s != null) {
  179.          this.textHeight = Integer.parseInt(s);
  180.       }
  181.  
  182.       this.textColor = this.getColor("text_color");
  183.       if (this.textColor == null) {
  184.          this.textColor = Color.white;
  185.       }
  186.  
  187.       this.enterTextColor = this.getColor("enter_text_color");
  188.    }
  189.  
  190.    public Color getColor(String param) {
  191.       String s = ((Applet)this).getParameter(param);
  192.       if (s != null) {
  193.          if (s.substring(0, 1).equals("#")) {
  194.             s = s.substring(1);
  195.             int i = Integer.parseInt(s, 16);
  196.             return new Color(i);
  197.          } else {
  198.             return null;
  199.          }
  200.       } else {
  201.          return null;
  202.       }
  203.    }
  204.  
  205.    public final synchronized void paint(Graphics g) {
  206.       if (this.loaded) {
  207.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  208.          int l = (this.field_1 - this.wiText) / 2;
  209.  
  210.          for(int i = 0; i < this.lines[this.field_3].length(); ++i) {
  211.             String letter = this.lines[this.field_3].substring(i, i + 1);
  212.             this.field_0.drawString(letter, l + (int)((double)(2 * this.textAmplitude) * Math.random()) - 3, this.field_2 / 2 + (int)((double)(2 * this.textAmplitude) * Math.random()) - 3);
  213.             l += this.field_4.stringWidth(letter);
  214.          }
  215.  
  216.          g.drawImage(this.buffer, 0, 0, this);
  217.       }
  218.    }
  219.  
  220.    public final void update(Graphics g) {
  221.       this.paint(g);
  222.    }
  223.  
  224.    public void start() {
  225.       if (this.thread == null) {
  226.          this.thread = new Thread(this);
  227.          this.thread.start();
  228.       }
  229.  
  230.    }
  231.  
  232.    public void stop() {
  233.       if (this.thread != null) {
  234.          this.thread = null;
  235.       }
  236.  
  237.       if (this.sound != null) {
  238.          this.sound.stop();
  239.       }
  240.  
  241.    }
  242.  
  243.    public void run() {
  244.       int c = 0;
  245.  
  246.       int m;
  247.       for(m = 0; (c = this.text.indexOf("#", c)) != -1; ++m) {
  248.          ++c;
  249.       }
  250.  
  251.       if (m != 0) {
  252.          int[] index = new int[m];
  253.          this.lines = new String[m + 1];
  254.  
  255.          for(m = 0; (c = this.text.indexOf("#", c)) != -1; ++m) {
  256.             index[m] = c;
  257.             String line;
  258.             if (m == 0) {
  259.                line = this.text.substring(0, index[0]);
  260.             } else {
  261.                line = this.text.substring(index[m - 1] + 1, index[m]);
  262.             }
  263.  
  264.             this.lines[m] = line;
  265.             ++c;
  266.          }
  267.  
  268.          this.lines[m] = this.text.substring(index[m - 1] + 1);
  269.       } else {
  270.          this.lines = new String[1];
  271.          this.lines[0] = this.text;
  272.       }
  273.  
  274.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  275.       this.field_0 = this.buffer.getGraphics();
  276.       int compteurText = 0;
  277.       this.field_0.setColor(this.textColor);
  278.       this.normalFont = this.field_0.getFont();
  279.       String fontName = ((Applet)this).getParameter("text_font_name");
  280.       if (fontName == null) {
  281.          fontName = this.normalFont.getName();
  282.       }
  283.  
  284.       int style = 0;
  285.       String s = ((Applet)this).getParameter("text_font_style");
  286.       if (s != null) {
  287.          if (s.equals("bold")) {
  288.             style = 1;
  289.          } else if (s.equals("italic")) {
  290.             style = 2;
  291.          } else if (s.equals("bold_italic")) {
  292.             style = 3;
  293.          } else {
  294.             style = 0;
  295.          }
  296.       }
  297.  
  298.       int enterStyle = style;
  299.       s = ((Applet)this).getParameter("text_enter_font_style");
  300.       if (s != null) {
  301.          if (s.equals("bold")) {
  302.             enterStyle = 1;
  303.          } else if (s.equals("italic")) {
  304.             enterStyle = 2;
  305.          } else if (s.equals("bold_italic")) {
  306.             enterStyle = 3;
  307.          } else {
  308.             style = 0;
  309.          }
  310.       }
  311.  
  312.       int enterTextHeight = 0;
  313.       s = ((Applet)this).getParameter("text_enter_font_height");
  314.       if (s != null) {
  315.          enterTextHeight = Integer.parseInt(s);
  316.       } else {
  317.          enterTextHeight = this.textHeight;
  318.       }
  319.  
  320.       try {
  321.          this.normalFont = new Font(fontName, style, this.textHeight);
  322.          this.enterFont = new Font(fontName, enterStyle, enterTextHeight);
  323.       } catch (Exception var10) {
  324.          this.normalFont = new Font(fontName, style, this.textHeight);
  325.          this.enterFont = new Font(fontName, enterStyle, enterTextHeight);
  326.       }
  327.  
  328.       this.field_0.setFont(this.normalFont);
  329.       this.field_4 = this.field_0.getFontMetrics();
  330.       this.field_3 = 0;
  331.       this.wiText = this.field_4.stringWidth(this.lines[this.field_3]);
  332.       this.loaded = true;
  333.  
  334.       while(true) {
  335.          ((Component)this).repaint();
  336.  
  337.          try {
  338.             Thread.sleep((long)this.pause);
  339.          } catch (InterruptedException var9) {
  340.             this.stop();
  341.          }
  342.  
  343.          compteurText += this.pause;
  344.          if (compteurText > this.textPause) {
  345.             compteurText = 0;
  346.             ++this.field_3;
  347.             if (this.field_3 >= this.lines.length) {
  348.                this.field_3 = 0;
  349.             }
  350.  
  351.             this.wiText = this.field_4.stringWidth(this.lines[this.field_3]);
  352.          }
  353.       }
  354.    }
  355.  
  356.    public URL giveURL(String url) {
  357.       try {
  358.          if (url.toUpperCase().startsWith("HTTP")) {
  359.             return new URL(url);
  360.          } else if (url.toUpperCase().startsWith("FTP")) {
  361.             int p = url.indexOf(":");
  362.             int p2 = url.indexOf(":", p + 1);
  363.             if (p2 != -1) {
  364.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  365.             }
  366.  
  367.             p = url.indexOf("%40");
  368.             if (p != -1) {
  369.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  370.             }
  371.  
  372.             return new URL(url);
  373.          } else {
  374.             return new URL(((Applet)this).getCodeBase(), url);
  375.          }
  376.       } catch (MalformedURLException e) {
  377.          System.out.println(e);
  378.          return null;
  379.       }
  380.    }
  381.  
  382.    public void mouseClicked(MouseEvent e) {
  383.    }
  384.  
  385.    public void mouseEntered(MouseEvent e) {
  386.       this.field_0.setFont(this.enterFont);
  387.       this.field_4 = this.field_0.getFontMetrics();
  388.       this.wiText = this.field_4.stringWidth(this.lines[this.field_3]);
  389.       if (this.enterTextColor != null) {
  390.          this.field_0.setColor(this.enterTextColor);
  391.       }
  392.  
  393.       if (this.statusBarText != null) {
  394.          ((Applet)this).showStatus(this.statusBarText);
  395.       }
  396.  
  397.       if (this.enterSound != null) {
  398.          this.enterSound.play();
  399.       }
  400.  
  401.       if (this.link != null) {
  402.          ((Component)this).setCursor(new Cursor(12));
  403.       }
  404.  
  405.    }
  406.  
  407.    public void mouseExited(MouseEvent e) {
  408.       this.field_0.setFont(this.normalFont);
  409.       this.field_4 = this.field_0.getFontMetrics();
  410.       this.wiText = this.field_4.stringWidth(this.lines[this.field_3]);
  411.       if (this.enterTextColor != null) {
  412.          this.field_0.setColor(this.textColor);
  413.       }
  414.  
  415.       if (this.link != null) {
  416.          ((Component)this).setCursor(new Cursor(0));
  417.       }
  418.  
  419.    }
  420.  
  421.    public void mousePressed(MouseEvent e) {
  422.       if (this.clicSound != null) {
  423.          this.clicSound.play();
  424.       }
  425.  
  426.       if (this.link != null) {
  427.          String target = ((Applet)this).getParameter("target");
  428.          if (target == null) {
  429.             target = "_blank";
  430.          }
  431.  
  432.          URL u = this.giveURL(this.link);
  433.          ((Applet)this).getAppletContext().showDocument(u, target);
  434.       }
  435.  
  436.    }
  437.  
  438.    public void mouseReleased(MouseEvent e) {
  439.    }
  440. }
  441.